package com.bnuboy.adapter;

import java.util.List;

import com.bnuboy.activity.R;


import net.oschina.app.common.BitmapManager;


import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListViewContentAdapter extends BaseAdapter {

	private Context ctx;
	private List<String> listItems;
	private LayoutInflater listContainer;
	private int itemViewResource;
	private BitmapManager im;
	static class ListItemView{
		public TextView tv;
		public ImageView face;
	}
	public ListViewContentAdapter(Context ctx, List<String> list, int resource){
		this.ctx = ctx;
		this.listItems = list;
		this.listContainer = LayoutInflater.from(ctx);
		this.itemViewResource = resource;
		im = new BitmapManager(BitmapFactory.decodeResource(ctx.getResources(), R.drawable.widget_dface_loading));
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.listItems.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ListItemView listItemView = null;
		if(convertView == null){
			convertView = this.listContainer.inflate(this.itemViewResource, null);
			listItemView = new ListItemView();
			listItemView.tv = (TextView)convertView.findViewById(R.id.tv);
			listItemView.face = (ImageView)convertView.findViewById(R.id.avatar);
			convertView.setTag(listItemView);
		}else{
			listItemView = (ListItemView)convertView.getTag();
		}
		String item = this.listItems.get(position);
		im.loadBitmap(item, listItemView.face);
		switch(position % 2){
		case 0:
			convertView.setBackgroundColor(Color.rgb(240, 240, 240));
			break;
		case 1:
			convertView.setBackgroundColor(Color.rgb(250,250,250));
			break;
		}
		//listItemView.tv.setText(item + position);
		return convertView;
	}

}
